package com.zgs.androidopengl

import android.opengl.GLSurfaceView
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.zgs.androidopengl.render.AirHockeyRender
import com.zgs.androidopengl.util.ESUtil.isSupportES2

class MainActivity : AppCompatActivity() {
    private var mGLSurfaceView: GLSurfaceView? = null
    private var mRenderSet = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mGLSurfaceView = GLSurfaceView(this)

        val supportES2 = isSupportES2(this)

        if (supportES2) {
            mGLSurfaceView!!.setEGLContextClientVersion(2)
            mRenderSet = true
            mGLSurfaceView!!.setRenderer(AirHockeyRender(this))
            setContentView(mGLSurfaceView)
        } else {
            Toast.makeText(this, "This device is not support OpenGL ES 2.0", Toast.LENGTH_LONG)
                .show()
        }
    }

    override fun onPause() {
        super.onPause()
        if (mRenderSet) {
            mGLSurfaceView!!.onPause()
        }
    }

    override fun onResume() {
        super.onResume()
        if (mRenderSet) {
            mGLSurfaceView!!.onResume()
        }
    }
}